#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2005;
ll n, a[N], dp[N][2][N];
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < i; j++) dp[i][0][j] = dp[i][1][j] = 0;
            //0
            for (int j = 0; j <= i - 2; j++) {
                if (a[i] == a[i - 1]) dp[i][0][j] = max(dp[i][0][j], dp[i - 1][0][j] + a[i]);
                else dp[i][0][j] = max(dp[i][0][j], dp[i - 1][0][j]);
            }
            dp[i][0][i - 1] = dp[i - 1][1][0];
            for (int j = 1; j <= i - 2; j++) {
                if (a[i] == a[j]) dp[i][0][i - 1] = max(dp[i][0][i - 1], dp[i - 1][1][j] + a[i]);
                else dp[i][0][i - 1] = max(dp[i][0][i - 1], dp[i - 1][1][j]);
            }
            //1
            for (int j = 0; j <= i - 2; j++) {
                if (a[i] == a[i - 1]) dp[i][1][j] = max(dp[i][1][j], dp[i - 1][1][j] + a[i]);
                else dp[i][1][j] = max(dp[i][1][j], dp[i - 1][1][j]);
            }
            dp[i][1][i - 1] = dp[i - 1][0][0];
            for (int j = 1; j <= i - 2; j++) {
                if (a[i] == a[j]) dp[i][1][i - 1] = max(dp[i][1][i - 1], dp[i - 1][0][j] + a[i]);
                else dp[i][1][i - 1] = max(dp[i][1][i - 1], dp[i - 1][0][j]);
            }
        }
//        for (int i = 1; i <= n; i++) {
//                cout<<i<<endl;
//            for (int j = 0; j < i; j++) {
//                cout << dp[i][0][j] << ' '<<dp[i][1][j]<<endl;
//            }
//        }
        ll ans = 0;
        for (int i = 0; i <= n - 1; i++) {
            ans = max(ans, max(dp[n][0][i], dp[n][1][i]));
        }
        cout << ans << endl;
    }

    return 0;
}
//8
//3 5 2 5 1 2 1 4
